from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from page_locators.userinfo_locator import UserinfoLocator as UL
from Common.base_page import BasePage

class UserinfoPage(BasePage):

    def __init__(self,driver):
        super().__init__(driver)

    def upload_userinfo_image(self,img_path):
        # self.driver.find_element(*UL.userinfo_loc).click()
        self.click_element(UL.userinfo_loc,"个人信息页面_个人信息修改模块_个人信息链接点击操作")
        sleep(2)

        # attr_src_value1 = self.driver.find_element_by_id('preview').get_attribute('src')

        # self.driver.find_element(*UL.preview_loc).click()
        self.click_element(UL.preview_loc,"个人信息页面_个人信息修改模块_头像点击操作")

        sleep(2)
        # frame = self.driver.find_element(*UL.frame_loc)
        # self.driver.switch_to.frame(frame)
        self.switch_into_frame(UL.frame_loc,"个人信息页面_个人信息修改模块_弹窗框切入操作")
        # self.driver.find_element(*UL.upload_file).send_keys(img_path)
        self.input_text(UL.upload_file,img_path,"个人信息页面_个人信息修改模块_图片上传操作")
        sleep(2)
        # self.driver.find_element(*UL.savebtn_loc).click()
        self.click_element(UL.savebtn_loc,"个人信息页面_个人信息修改模块_保存操作")

        # attr_src_value2 = self.driver.find_element_by_id('preview').get_attribute('src')
        #
        # if attr_src_value1 != attr_src_value2:
        #     print('PASS,头像修改成功')
        # else:
        #     print('FAIL,头像修改失败')
        #
        # self.driver.switch_to.default_content()






